#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<vector>
#include<queue>
using namespace std;
const int N = 10010;
int f[N];
vector<int> as[N];
int len[N];
int n;
vector<int> edge[N];
int id[N];
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        int b = 0;
        cin >> b >> len[b];
        int j;
        while (cin >> j, j)
        {
            edge[j].push_back(b);
            id[b]++;
        }
    }
    queue<int> q;
    for (int i = 1; i <= n; i++)
    {
        if (id[i] == 0)
        {
            q.push(i);
        }
    }
    int ret = 0;
    while (q.size())
    {
        int a = q.front();
        q.pop();
        f[a] += len[a];
        ret = max(ret, f[a]);
        for (auto e : edge[a])
        {
            f[e] = max(f[a], f[e]);
            id[e]--;
            if (id[e] == 0)
            {
                q.push(e);
            }
        }
    }
    cout << ret;
    return 0;
}